<template>
  <div class="huiyuankaika">
    <div style="padding-bottom: 15px">
      <div class="detail-page" v-if="module.modules && module.modules[0] && module.modules[0].pic">
        <img
          class="detail-page-img"
          style="height: 120px"
          :src="fileBaseUrl + module.modules[0].pic"
        />
      </div>
      <div style="background: #f6f6f6">
        <div class="featurelist">
          <div
            v-for="item in featureList"
            :key="item.id"
            class="feature-item"
            @click="setActiveId(item.id)"
          >
            <div
              class="title"
              :class="item.id === activeId ? 'titleActive' : 'title'"
            >
              {{ item.categoryName }}
            </div>
            <div
              :class="item.id === activeId ? 'point' : ' '"
              :style="{
                width: item.width,
                background: item.id === activeId ? '#FFB72F' : '',
              }"
            ></div>
          </div>
        </div>
      </div>
      <div class="open-card-gift flexCS">
        <div class="open-card-gift-item colCA">
          <div>
            <img
              style="width: 28px; height: 28px"
              :src="require('@/assets/icon/help.png')"
              class="gift-icon"
            />
          </div>
          <div class="circle"></div>
          <div class="_h2" style="color: #fff; background: #ffb72f">
            小程序查看
          </div>
          <div class="_h3">小程序查看</div>
        </div>
      </div>
      <div
        class="flex-x-center-center open-card-btn"
        style="background: #ffb72f; color:#fff "
      >
        立即开通领取奖励
      </div>
    </div>
  </div>
</template>

<script>
import { getAllVipCardList } from "@/api/vip";
export default {
  props: {
    module: {
      type: Object,
    },
    fileBaseUrl: {
      type: String,
    },
  },
  data() {
    return {
      a: {b:[1]},
      featureList: [],
      activeId: null,
    };
  },
  watch: {
    'module.modules': {
      handler() {
        this.$forceUpdate()
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    this.getAllVipCardList();
  },
  methods: {
    //feature宽度适配
    handleFeatureList() {
      if(!this.module.modules) return
      let featureList = this.module.modules;
      featureList.forEach((item) => {
        if (item.categoryName) {
          let len = item.categoryName.length;
          if (len == 4) {
            item.width = "75px";
          } else if (len == 3) {
            item.width = "50px";
          } else if (len == 2) {
            item.width = "42.5px";
          } else {
            item.width = "50px";
          }
        }
      });
    },
    getAllVipCardList() {
      getAllVipCardList().then((res) => {
        this.featureList = res.data.filter((item) => item.status);
        this.activeId = this.featureList[0].id;
        this.handleFeatureList();
      });
    },
    setActiveId(id) {
      if (this.activeId === id) return;
      this.activeId = id;
    },
  },
};
</script>

<style lang="scss" scoped>
.detail-page {
  overflow: hidden;
  padding: 0px 10.5px;
  .detail-page-img {
    border-radius: 10px;
  }
  margin-bottom: 16px;
}
.featurelist {
  display: flex;
  flex-wrap: nowrap;
  padding: 16px 0px;
  width: 100%;
  align-items: center;
  background: #f6f6f6;
  overflow: hidden;
  .feature-item {
    flex-shrink: 0;
    font-family: PingFang SC;
    font-weight: 400;
    color: #353535;
    text-align: center;
    margin: 0 8px;
    padding: 0px 10px;
    position: relative;
    .titleActive {
      font-size: 16px;
      font-weight: bold;
    }
    .title {
      font-size: 14px;
      padding: 0px 5px;
    }
    .point {
      background-color: #03c1b6;
      opacity: 0.5;
      width: 42px;
      height: 8px;
      position: absolute;
      left: 50%;
      top: 48%;
      transform: translateX(-50%);
      z-index: 1;
      border-bottom-right-radius: 5px;
      border-top-left-radius: 5px;
    }
    .titlep {
      font-size: 12px;
      color: #888888;
      margin-top: 12px;
    }
    .title {
      font-size: 15px;
      z-index: 5;
      font-family: PingFang SC;
      position: relative;
    }
  }
}
.member-msg {
  background: #ffffff;
  box-shadow: 0px 1px 41px 0px rgba(0, 0, 0, 0.06);
  border-radius: 10px;
  padding: 25px 0px 22px 0px;
}
/*开卡礼包*/
.open-card-gift-container {
  .gift-container-title {
    margin-left: 10px;
    margin-bottom: 21px;
    font-size: 16px;
    font-weight: bold;
    color: rgba(0, 0, 0, 1);
    line-height: 16px;

    .sub-title {
      display: inline;
      font-size: 13px;
      font-weight: bold;
      color: rgba(178, 178, 178, 1);
      line-height: 16px;
    }
  }
}
.customOpenRewards-circle {
  width: 6px;
  height: 6px;
  background: #353535;
  border-radius: 50%;
}
.customOpenRewards {
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #000000;
  padding: 0px 6px 50px 14px;
  .line {
    width: 100%;
    height: 1px;
    background: #eaeaea;
    margin-bottom: 19px;
  }
  .customOpenRewardsItem {
    margin-bottom: 6px;
  }
  .title {
    margin-left: 6px;
  }
}

.open-card-gift {
  flex-wrap: wrap;
  padding: 0px 10px;
  align-items: flex-start;
  padding-top: 10px;
  padding-bottom: 25px;
}

.open-card-gift-item {
  /* margin: 0px 30rpx; */
  margin-top: 24px;
  position: relative;
  width: 25%;
  /* flex: 1; */

  .gift-icon {
    margin-left: 27px;
  }

  .circle {
    width: 46px;
    height: 46px;
    border: 1px solid #cccccc;
    border-radius: 23px;
    position: absolute;
    top: -10%;
    left: 50%;
    transform: translateX(-50%);
  }
  ._h2 {
    padding: 0 5px;
    position: relative;
    z-index: 1;
    min-width: 45px;
    height: 18px;
    background: rgba(252, 177, 66, 1);
    border-radius: 9px;
    font-size: 10px;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: rgba(0, 0, 0, 1);
    text-align: center;
    line-height: 18px;
  }

  ._h3 {
    text-align: center;
    /* width: 130px; */
    margin-top: 10px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: rgba(0, 0, 0, 1);
    line-height: 16px;
  }
}
.open-card-btn {
  width: 300px;
  height: 44px;
  background: #03c1b6;
  border-radius: 22px;
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #ffffff;
  margin: 0 auto;
}
.srcoll-div {
  padding: 0px 10px 10px 10px;
  .card-item {
    font-weight: 400;
    //margin-right: 73px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 1;
    flex-shrink: 0;
    .card-item-val {
      font-size: 29px;
      font-family: Source Han Sans SC;
      color: #000000;
      margin-bottom: 11px;
    }
    .card-item-key {
      font-size: 13px;
      font-family: PingFang SC;
      color: #888888;
    }
  }
}
.upgrade-btn {
  position: relative;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 333px;
  height: 44px;
  background: #fef6f6;
  border-radius: 10px;
  margin-top: 20px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #e74d4d;
}
</style>
